package com.stone.serverless.web.listener;

import cn.hutool.core.util.ObjectUtil;
import com.stone.serverless.auth.interceptor.StoneHandlerInterceptor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.ServletRequestHandledEvent;

/**
 * @Description: TODO
 * @Author: MECHREVO
 * @Date: 2022/1/27 10:39
 * @Version: 1.0.0
 */
@Component
public class ServletRequestHandledListener {

    private StoneHandlerInterceptor stoneHandlerInterceptor;

    public void setStoneHandlerInterceptor(StoneHandlerInterceptor stoneHandlerInterceptor) {
        this.stoneHandlerInterceptor = stoneHandlerInterceptor;
    }

    @EventListener(classes = ServletRequestHandledEvent.class)
    public void listener(ServletRequestHandledEvent event) {
        //WebComponentConsumer instance = WebComponentConsumer.INSTANCE;
        //if (ObjectUtil.isNull(instance)) {
        //    return;
        //}
        if (null != stoneHandlerInterceptor) {
            stoneHandlerInterceptor.finishRequest();
        }
    }
}
